home *** CD-ROM | disk | FTP | other *** search
/ NetObjects Fusion 7 / Fusion7.iso / NetObjects Fusion / data1.cab / Fsi / PhotoGallery / PhotoGallery.js < prev    next >
Encoding:
JavaScript  |  2002-10-18  |  61.7 KB  |  2,244 lines

  1. ////////////////////////////////////////////////////////////////////////////////
  2. // Class Dictionary
  3.  
  4.     function Dictionary() {
  5.         Dictionary.prototype.load = Dictionary_load;
  6.         Dictionary.prototype.get = Dictionary_get;
  7.         if (arguments.length > 1)
  8.             this.caseSensitive = arguments[1];
  9.         if (arguments.length > 0)
  10.             this.load(arguments[0]);
  11.     }
  12.  
  13.     function Dictionary_load(fileName) {
  14.         var app2 = new ActiveXObject("FSI.FSIApplication2");
  15.         var lines = app2.ReadFile(fileName).split('\n');
  16.         var i;
  17.         for (i = 0;i < lines.length;i++) {
  18.             if (lines[i].length == 0)
  19.                 continue;
  20.             var sep = lines[i].indexOf(lines[i].charAt(0), 1);
  21.             if (sep > 1) {
  22.                 var key = lines[i].substring(1, sep);
  23.                 if (this.caseSensitive)
  24.                     key = key.toLowerCase();
  25.                 this[key] = lines[i].substr(sep + 1);
  26.             }
  27.         }
  28.     }
  29.  
  30.     function Dictionary_get(key) {
  31.         var k = this.caseSensitive ? key.toLowerCase() : key;
  32.         if (this.hasOwnProperty(k))
  33.             return this[k];
  34.         else if (arguments.length > 1)
  35.             return arguments[1];
  36.         return key;
  37.     }
  38.  
  39. ////////////////////////////////////////////////////////////////////////////////
  40. // The dictionary used for templates and styles names
  41.  
  42.     var dictionary = new Dictionary("./PhotoGallery/Dictionary.txt", true);
  43.  
  44.  
  45.     function settingsDefinition(template, subTemplate, subTemplateText, description, preview, path)
  46.     {
  47.         this.lsMaxWidth = 100;
  48.         this.lsMaxHeight = 100;
  49.         this.lsWidth = 100;
  50.         this.lsHeight = 100;
  51.         this.ptMaxWidth = 100;
  52.         this.ptMaxHeight = 100;
  53.         this.ptWidth = 100;
  54.         this.ptHeight = 100;
  55.         this.quality = 85;
  56.         this.template = template;
  57.         this.subTemplate = subTemplate;
  58.         this.subTemplateText = subTemplateText;
  59.         this.description = description;
  60.         this.preview = preview;
  61.         this.path = path;
  62.         this.currentTemplate = '';
  63.         this.currentSubTemplate = '';
  64.         this.origTemplate = '';
  65.         this.origSubTemplate = '';
  66.         this.templateSettings = '';
  67.         this.titleSet = true;
  68.         this.titleEnabled = true;
  69.         this.titleDeleteRow = false;
  70.         this.borderEnabled = false;
  71.         this.borderColor = 0;
  72.         this.borderWidth = 0;
  73.         this.origBorderColor = 0;
  74.         this.origBorderWidth = 0;
  75.         this.spacingEnabled = false;
  76.         this.horizontalSpacing = 0;
  77.         this.verticalSpacing = 0;
  78.     }
  79.  
  80.     function imageAttributes()
  81.     {
  82.         this.flags = 0;
  83.         this.width = 0;
  84.         this.height = 0;
  85.         this.quality = 0;
  86.         this.format = 'jpg';
  87.     }
  88.  
  89.     function imageAttributesEqual(o1, o2)
  90.     {
  91.         return o1.flags == o2.flags &&
  92.             o1.width == o2.width &&
  93.             o1.height == o2.height &&
  94.             o1.quality == o2.quality &&
  95.             o1.format == o2.format;
  96.     }
  97.  
  98.     function imageObjectAttributes(displayAttributes, indexAttributes)
  99.     {
  100.         this.title = '';
  101.         this.description = '';
  102.         this.image = '';
  103.         this.rotation = 0;
  104.         this.display = displayAttributes;
  105.         this.index = indexAttributes;
  106.     }
  107.  
  108.     function imageAttributesToString(o)
  109.     {
  110.         return '' +
  111.         o.flags + ', ' +
  112.         o.width + ', ' +
  113.         o.height + ', ' +
  114.         o.quality + ', ' +
  115.         o.format;
  116.     }
  117.  
  118.     function imageObjectAttributesToString(o)
  119.     {
  120.         return '' +
  121.         o.title + ', ' +
  122.         o.description + ', ' +
  123.         o.image + ', ' +
  124.         imageAttributesToString(o.displayAttributes) + ', ' +
  125.         imageAttributesToString(o.indexAttributes);
  126.     }
  127.  
  128.     function copyImageAttributes(f, t)
  129.     {
  130.         t.flags = f.flags;
  131.         t.width = f.width;
  132.         t.height = f.height;
  133.         t.quality = f.quality;
  134.         t.format = f.format;
  135.     }
  136.  
  137.     function copyImageObjectAttributes(f, t)
  138.     {
  139.         t.title = f.title;
  140.         t.description = f.description;
  141.         t.image = f.image;
  142.         t.rotation = f.rotation;
  143.         copyImageAttributes(f.index, t.index);
  144.         copyImageAttributes(f.display, t.display);
  145.     }
  146.  
  147.     var fDisplayImage = new imageAttributes();
  148.     var fIndexImage = new imageAttributes();
  149.     var oDisplayImage = new imageAttributes();
  150.     var oIndexImage = new imageAttributes();
  151.     
  152.     var fImage = new imageObjectAttributes(fDisplayImage, fIndexImage);
  153.     var oImage = new imageObjectAttributes(oDisplayImage, oIndexImage);
  154.     var currentImage;
  155.  
  156.     var fIndexSettings;
  157.     var fDisplaySettings;
  158.     var currentSettings;
  159.     var currentTemplateSettings;
  160.  
  161.     var INDEX_IS_TABLE            = 0x00000001;
  162.     var INDEX_INCLUDE_TITLE        = 0x00000002;
  163.     var DISPLAY_LAYOUT_MASK        = 0x0000000f;
  164.     var TABLE_GENERATED_MASK     = 0x00000800;
  165.  
  166.     var numoftabs=3;
  167.     var currentTab = -1;
  168.     var numoftabs1=2;
  169.     var currentTab1 = -1;
  170.     var initialTab1 = 0;
  171.     var app = new ActiveXObject( "FSI.FSIApplication" );
  172.     var app2 = new ActiveXObject( "FSI.FSIApplication2" );
  173.     var theSelection;
  174.     var theTable;
  175.     var selection;
  176.     var indexCatalog;
  177.     var displayCatalog;
  178.     var current = 1;
  179.     var index = -1;
  180.     var indices = new Array();
  181.     var positions = new Array();
  182.     var count = 0;
  183.     var seqChanged = false;
  184.     var isUpdating = false;
  185.     var forceUpdate = false;
  186.     var isValid = false;
  187.     var fFieldName;
  188.     var isInitial = window.dialogArguments;
  189.     var indexModified = false;
  190.     var displayModified = false;
  191.     var listInit = false;
  192.             
  193.     function ListCtrl_OnSelect()
  194.     {
  195.         if (isUpdating || (!forceUpdate && index == FSIListCtrl.Index))
  196.             return;
  197.         updateItem();
  198.         updateTab();
  199.     }
  200.     
  201.     function ListCtrl_OnMove()
  202.     {
  203.         isUpdating = true;
  204.         var from = FSIListCtrl.Index;
  205.         var to = FSIListCtrl.DropIndex;
  206.         var f = indices[from];
  207.         
  208.         if (to > from)
  209.         {
  210.             for (var i = from; i < to - 1; i++)
  211.                 indices[i] = indices[i + 1];
  212.  
  213.             indices[to - 1] = f;
  214.         }
  215.         else
  216.         {
  217.             for (var i = from; i > to; i--)
  218.                 indices[i] = indices[i - 1];
  219.  
  220.             indices[to] = f;
  221.         }
  222.  
  223.         index = to;
  224.         selection.SetIndex(indices[index]);
  225.         FSIListCtrl.Move(from, to);
  226.         seqChanged = true;
  227.         FSIListCtrl.focus();
  228.         isUpdating = false;
  229.     }
  230.     
  231.     function ListCtrl_OnReady()
  232.     {
  233.         listInit = true;
  234.         FSIListCtrl.SetSize(ListCtrl.clientWidth - 2, ListCtrl.clientHeight - 2);
  235.         FSIListCtrl.MoveCursor = true;
  236.         updateCatalog();
  237.         tabshow(initialTab1, false);
  238.     }
  239.  
  240.  
  241.     function initTemplateCombo(o, path, s)
  242.     {
  243.         var iter = new ActiveXObject('FSI.FSIDirIterator');
  244.         var i = 0;
  245.         iter.DefineSearch('.\\PhotoGallery\\' + path, '*');
  246.  
  247.         for (;;)
  248.         {
  249.             var p = iter.GetNext();
  250.             if (!p.length)
  251.                 break;
  252.             var q = p.split('.');
  253.             if (q.length > 1)
  254.             {
  255.                 if (q[q.length - 1].split('\\').length == 1)
  256.                     continue;
  257.             }
  258.             p = p.split('\\');
  259.             p = p[p.length - 1];
  260.             var theOption = document.createElement("OPTION");
  261.             theOption.value = p;
  262.             theOption.text = dictionary.get(p);
  263.             for (i = 0;i < o.options.length && theOption.text.toLowerCase() > o.options(i).text.toLowerCase();i++);
  264.             o.options.add(theOption, i);
  265.         }
  266.         o.selectedIndex = 0;
  267.         for (i = o.options.length;--i >= 0;) {
  268.             if (o.options.item(i).value == s) {
  269.                 o.selectedIndex = i;
  270.                 break;
  271.             }
  272.         }
  273.     }
  274.         
  275.     function handleInfo(info, settings)
  276.     {
  277.         var s = info.split('\n');
  278.  
  279.         for (var i = 0; i < s.length; i++)
  280.         {
  281.             var p = s[i].split('=');
  282.  
  283.             if (p[0] == 'template')
  284.                 settings.currentTemplate = p[1];
  285.             else if (p[0] == 'subtemplate')
  286.                 settings.currentSubTemplate = p[1];
  287.             else if (p[0] == 'flags')
  288.                 settings.flags = p[1] - 0;
  289.             else if (p[0] == 'width')
  290.                 settings.width = p[1] - 0;
  291.             else if (p[0] == 'height')
  292.                 settings.height = p[1] - 0;
  293.             else if (p[0] == 'quality')
  294.                 settings.quality = p[1] - 0;
  295.             else if (p[0] == 'borderColor')
  296.                 settings.borderColor = p[1] - 0;
  297.             else if (p[0] == 'borderWidth')
  298.                 settings.borderWidth = p[1] - 0;
  299.         }
  300.     }
  301.  
  302.     function init()
  303.     {
  304.         fIndexSettings = new settingsDefinition(template, templateStyle, styleText, indexDescription, indexPreview, 'Thumbnail');
  305.         fDisplaySettings = new settingsDefinition(wrapper, wrapperOptions, wrapperOptionsText, displayDescription, displayPreview, 'Photo');
  306.         theSelection = app.GetCurrentSelection();
  307.         if (!theSelection)
  308.             return;
  309.             
  310.         theTable = theSelection.GetTable();
  311.         indexCatalog = theSelection.GetIndexCatalog();
  312.         displayCatalog = theSelection.GetDisplayCatalog();
  313.         app2.SetDialogTitle(dictionary.get('PhotoGalleryTitle') + theTable.Name);
  314.         selection = app.GetGlobalSelection1();
  315.  
  316.         if ((indexCatalog.Flags & INDEX_IS_TABLE) || window.dialogArguments)
  317.             formatType[1].checked = true;
  318.         else
  319.             formatType[0].checked = true;
  320.  
  321.         handleInfo(indexCatalog.Info, fIndexSettings);
  322.         fIndexSettings.origTemplate = fIndexSettings.currentTemplate;
  323.         fIndexSettings.origSubTemplate = fIndexSettings.currentSubTemplate;
  324.         fIndexSettings.origBorderColor = fIndexSettings.borderColor;
  325.         fIndexSettings.origBorderWidth = fIndexSettings.borderWidth;
  326.         handleInfo(displayCatalog.Info, fDisplaySettings);
  327.         fDisplaySettings.origTemplate = fDisplaySettings.currentTemplate;
  328.         fDisplaySettings.origSubTemplate = fDisplaySettings.currentSubTemplate;
  329.         fDisplaySettings.origBorderColor = fDisplaySettings.borderColor;
  330.         fDisplaySettings.origBorderWidth = fDisplaySettings.borderWidth;
  331.  
  332.         initTemplateCombo(template, 'Thumbnail', fIndexSettings.currentTemplate);
  333.         initTemplateCombo(templateStyle, 'Thumbnail\\' + template.options[template.selectedIndex].value + '\\options', fIndexSettings.currentSubTemplate);
  334.         initTemplateCombo(wrapper, 'Photo', fDisplaySettings.currentTemplate);
  335.         initTemplateCombo(wrapperOptions, 'Photo\\' + wrapper.options[wrapper.selectedIndex].value + '\\options', fDisplaySettings.currentSubTemplate);
  336.  
  337.         if (indexCatalog.Settings.length)
  338.         {
  339.             updateSettings(indexCatalog.Settings, fIndexSettings);
  340.             fIndexSettings.lsMaxWidth = indexCatalog.LsMaxWidth;
  341.             fIndexSettings.lsMaxHeight = indexCatalog.LsMaxHeight;
  342.             fIndexSettings.lsMinWidth = indexCatalog.LsMinWidth;
  343.             fIndexSettings.lsMinHeight = indexCatalog.LsMinHeight;
  344.             fIndexSettings.lsWidth = indexCatalog.LsWidth;
  345.             fIndexSettings.lsHeight = indexCatalog.LsHeight;
  346.             fIndexSettings.ptMaxWidth = indexCatalog.PtMaxWidth;
  347.             fIndexSettings.ptMaxHeight = indexCatalog.PtMaxHeight;
  348.             fIndexSettings.ptMinWidth = indexCatalog.PtMinWidth;
  349.             fIndexSettings.ptMinHeight = indexCatalog.PtMinHeight;
  350.             fIndexSettings.ptWidth = indexCatalog.PtWidth;
  351.             fIndexSettings.ptHeight = indexCatalog.PtHeight;
  352.             fIndexSettings.horizontalSpacing = indexCatalog.HorizontalSpacing;
  353.             fIndexSettings.verticalSpacing = indexCatalog.VerticalSpacing;
  354.         }
  355.         else
  356.             updateInfo(fIndexSettings);
  357.  
  358.         if (displayCatalog.Settings.length)
  359.         {
  360.             updateSettings(displayCatalog.Settings, fDisplaySettings);
  361.             fDisplaySettings.lsMaxWidth = displayCatalog.LsMaxWidth;
  362.             fDisplaySettings.lsMaxHeight = displayCatalog.LsMaxHeight;
  363.             fDisplaySettings.lsMinWidth = displayCatalog.LsMinWidth;
  364.             fDisplaySettings.lsMinHeight = displayCatalog.LsMinHeight;
  365.             fDisplaySettings.lsWidth = displayCatalog.LsWidth;
  366.             fDisplaySettings.lsHeight = displayCatalog.LsHeight;
  367.             fDisplaySettings.ptMaxWidth = displayCatalog.PtMaxWidth;
  368.             fDisplaySettings.ptMaxHeight = displayCatalog.PtMaxHeight;
  369.             fDisplaySettings.ptMinWidth = displayCatalog.PtMinWidth;
  370.             fDisplaySettings.ptMinHeight = displayCatalog.PtMinHeight;
  371.             fDisplaySettings.ptWidth = displayCatalog.PtWidth;
  372.             fDisplaySettings.ptHeight = displayCatalog.PtHeight;
  373.         }
  374.         else
  375.             updateInfo(fDisplaySettings);
  376.  
  377.         updatePreview(fIndexSettings);
  378.         updatePreview(fDisplaySettings);
  379.  
  380.         fIndexSettings.borderColor = fIndexSettings.origBorderColor;
  381.         fIndexSettings.borderWidth = fIndexSettings.origBorderWidth;
  382.         fDisplaySettings.borderColor = fDisplaySettings.origBorderColor;
  383.         fDisplaySettings.borderWidth = fDisplaySettings.origBorderWidth;
  384.  
  385.         if (templateStyle.options.length)
  386.         {
  387.             colorStyleDiv.className="tabhide";
  388.             templateStyleDiv.className="tabshow";
  389.         }
  390.         else
  391.         {
  392.             templateStyleDiv.className="tabhide";
  393.             
  394.             if (fIndexSettings.borderEnabled)
  395.             {
  396.                 colorStyleDiv.className="tabshow";
  397.                 bordercolorctl.style.backgroundColor = fIndexSettings.borderColor;
  398.                 borderwidth.value = fIndexSettings.borderWidth;
  399.             }
  400.             else
  401.                 colorStyleDiv.className="tabhide";
  402.         }
  403.         
  404.         if (fIndexSettings.spacingEnabled)
  405.         {
  406.             cellSpacingDiv.className="tabshow";
  407.             cellspacing.value = fIndexSettings.horizontalSpacing;
  408.         }
  409.         else
  410.             cellSpacingDiv.className="tabhide";
  411.         
  412.         if (wrapperOptions.options.length)
  413.         {
  414.             displayColorStyleDiv.className="tabhide";
  415.             wrapperOptionsDiv.className="tabshow";
  416.         }
  417.         else
  418.         {
  419.             wrapperOptionsDiv.className="tabhide";
  420.             
  421.             if (fDisplaySettings.borderEnabled)
  422.             {
  423.                 displayColorStyleDiv.className="tabshow";
  424.                 displaybordercolorctl.style.backgroundColor = fDisplaySettings.borderColor;
  425.                 displayborderwidth.value = fDisplaySettings.borderWidth;
  426.             }
  427.             else
  428.                 displayColorStyleDiv.className="tabhide";
  429.         }
  430.  
  431.         fFieldName = theSelection.BannerNameField;
  432.         titleInBanner.checked = fFieldName.length;
  433.  
  434.         updateIndexTab(formatType[1].checked)
  435.         textLink.value = indexCatalog.Name;
  436.         columns.selectedIndex = indexCatalog.ColNo - 1;
  437.         includeTitle.checked = indexCatalog.Flags & INDEX_INCLUDE_TITLE;
  438.         layoutSelect[displayCatalog.Flags & DISPLAY_LAYOUT_MASK].checked = true;
  439.  
  440.         setDialogSize(dictionary.get('PhotoGalleryWidth'), dictionary.get('PhotoGalleryHeight'));
  441.  
  442.         var theMode = app.GetInstVar('mode') - 0;
  443.         if (window.dialogArguments || (theMode == 1 && (indexCatalog.Flags & INDEX_IS_TABLE) == 0))
  444.             theMode = 0;
  445.         if (theMode < 0)
  446.         {
  447.             initialTab1 = 1;
  448.             theMode = 0;
  449.         }
  450.  
  451.         if (selection)
  452.         {
  453.             selection.SetTable(theTable);
  454.             selection.SetIndex(0);
  455.             imageNo.innerText = selection.Count();
  456.  
  457.             for (var i = 0; i < selection.Count(); i++)
  458.             {
  459.                 var pos = selection.GetField('Position') - 0;
  460.                 positions[count] = pos;
  461.                 var p = count;
  462.                 for (var j = 0; j < count; j++)
  463.                 {
  464.                     if (pos < positions[indices[j]])
  465.                     {
  466.                         p = j;
  467.                         break;
  468.                     }
  469.                 }
  470.                 if (p < count)
  471.                 {
  472.                     for (var j = count; j > p; j--)
  473.                         indices[j] = indices[j - 1];
  474.                 }
  475.                 indices[p] = i;
  476.                 count++;
  477.                 selection.NextRecord();
  478.             }
  479.         }
  480.  
  481.         if (theMode)
  482.             currentSettings = (currentTab1 ? fDisplaySettings : fIndexSettings);
  483.         tabshow(theMode, true);
  484.         if (theMode == 0)
  485.             FSIListCtrl.focus();
  486.     }
  487.     
  488.     function newRollover(imgName,imgFiles)
  489.     {
  490.         if (document.images)
  491.         {
  492.             imgFiles=imgFiles+",";
  493.             imgNo=1;
  494.             while(imgFiles.indexOf(',')>0)
  495.             {
  496.                 imgFile=imgFiles.substring(0,imgFiles.indexOf(','));
  497.                 imgFiles=imgFiles.substring(imgFiles.indexOf(',')+1,imgFiles.length);
  498.                 eval(imgName+"_urc_"+imgNo+"=new Image();");
  499.                 eval(imgName+"_urc_"+imgNo+".src='"+imgFile+"';");
  500.                 imgNo++;
  501.             }
  502.         }
  503.     }
  504.     
  505.     function roll(img,on)
  506.     {
  507.         eval("document.images['"+img+"'].src="+img+"_urc_"+on+".src;");
  508.     }
  509.         
  510.     newRollover("tabimg_1b","../resources/images/tab-right-low.gif,../resources/images/tab-left-hi.gif,../resources/images/pix.gif");
  511.  
  512.     for (i=0;i!=numoftabs;i++) {
  513.         newRollover("tabimg"+i+"a","../resources/images/tab-left-low.gif,../resources/images/tab-right-hi.gif,../resources/images/tab-top-hi.gif");
  514.         newRollover("tabimg"+i+"b","../resources/images/tab-right-low.gif,../resources/images/tab-left-hi.gif,../resources/images/tab-top-hi.gif");
  515.     }
  516.  
  517.     newRollover("tabimg"+numoftabs+"a","../resources/images/tab-left-low.gif,../resources/images/tab-right-hi.gif,../resources/images/pix.gif");
  518.  
  519.     newRollover("tabimg_1b1","../resources/images/tab-right-low.gif,../resources/images/tab-left-hi.gif,../resources/images/pix.gif");
  520.  
  521.     for (i=0;i!=numoftabs1;i++) {
  522.         newRollover("tabimg1"+i+"a","../resources/images/tab-left-low.gif,../resources/images/tab-right-hi.gif,../resources/images/tab-top-hi.gif");
  523.         newRollover("tabimg1"+i+"b","../resources/images/tab-right-low.gif,../resources/images/tab-left-hi.gif,../resources/images/tab-top-hi.gif");
  524.     }
  525.  
  526.     newRollover("tabimg1"+numoftabs1+"a","../resources/images/tab-left-low.gif,../resources/images/tab-right-hi.gif,../resources/images/pix.gif");
  527.  
  528.     function tabshow(tabnum, maintab) 
  529.     {
  530.         var tabno = (maintab ? numoftabs : numoftabs1);
  531.         var s = (maintab ? '' : '1');
  532.         var theTab = (maintab ? currentTab : currentTab1);
  533.         
  534.         if (maintab &&
  535.             ((currentTab == 1 && fIndexSettings.origTemplate != template.options[template.selectedIndex].value) ||
  536.             (currentTab == 2 && fDisplaySettings.origTemplate != wrapper.options[wrapper.selectedIndex].value)))
  537.         {
  538.             setImageSizeAll();
  539.         }
  540.         
  541.         if (theTab >= 0)
  542.             document.all["tabText"+s+theTab].className="tabStyle";
  543.         document.all["tabText"+s+tabnum].className="tabStyleHl";
  544.  
  545.         // turn all tabs off
  546.         roll("tabimg_1b"+s,3);
  547.         if (maintab)
  548.         {
  549.             document.all["tab_1bot"+s].style.backgroundImage="url('../resources/images/tab-bottom.gif')";
  550.             currentTemplateSettings = (tabnum ? (tabnum == 2 ? fDisplaySettings : fIndexSettings) : null);
  551.         }
  552.         
  553.         for (i=0;i!=tabno;i++) 
  554.         {
  555.             roll("tabimg"+s+i+"a",1);
  556.             roll("tabimg"+s+i+"b",1);
  557.             document.all["tab"+s+i].style.backgroundImage="url('../resources/images/tab-top-low.gif')";
  558.             document.all["tab"+s+i+"bot"].style.backgroundImage="url('../resources/images/tab-bottom.gif')";
  559.             if (maintab)
  560.                 document.all["content"+s+i].className="tabhide";
  561.         }
  562.  
  563.         roll("tabimg"+s+tabno+"a",3);
  564.         document.all["tab"+s+tabno+"bot"].style.backgroundImage="url('../resources/images/tab-bottom.gif')";
  565.  
  566.         // turn on the right tab now...
  567.         
  568.         if (tabnum==0) {
  569.              roll("tabimg_1b"+s,2);
  570.         }
  571.         else {
  572.             roll("tabimg"+s+(tabnum-1)+"b",2);
  573.         }
  574.         roll("tabimg"+s+tabnum+"a",3);
  575.         roll("tabimg"+s+tabnum+"b",3);
  576.         roll("tabimg"+s+(tabnum+1)+"a",2);
  577.         document.all["tab"+s+tabnum].style.backgroundImage="url('../resources/images/tab-top-hi.gif')";
  578.         document.all["tab"+s+tabnum+"bot"].style.backgroundImage="url('../resources/images/pix.gif')";
  579.         if (maintab)
  580.         {
  581.             document.all["content"+s+tabnum].className="tabshow";
  582.             currentTab = tabnum;
  583.             
  584.             if (currentImage && currentTab == 0 && (currentImage.flags & TABLE_GENERATED_MASK) == 0)
  585.                 updateTab();
  586.         }
  587.         else
  588.         {
  589.             getFromTab();
  590.             currentTab1 = tabnum;
  591.             currentImage = (currentTab1 ? fDisplayImage : fIndexImage);
  592.             currentSettings = (currentTab1 ? fDisplaySettings : fIndexSettings);
  593.             updateTab();
  594.         }
  595.     }
  596.  
  597.     function setImageType()
  598.     {
  599.         if (imageType.selectedIndex)
  600.         {
  601.             jpeg.className="tabhide";
  602.             gif.className="tabshow";
  603.             prop.innerText = 'Palette:';
  604.             FSIImage.Quality = colors.selectedIndex + 1;
  605.             FSIImage.Format = 'gif';
  606.             FSIImage.Palette = palette.selectedIndex;
  607.         }
  608.         else    
  609.         {
  610.             gif.className="tabhide";
  611.             jpeg.className="tabshow";
  612.             prop.innerText = dictionary.get('LabelQuality');
  613.             FSIImage.Quality = quality.value - 0;
  614.             FSIImage.Format = 'jpg';
  615.             FSIImage.Palette = 0;
  616.         }
  617.  
  618.         displayImage();
  619.     }
  620.  
  621.     function setPalette()
  622.     {
  623.         FSIImage.Palette = palette.selectedIndex;
  624.         displayImage();
  625.     }
  626.  
  627.     function setColors()
  628.     {
  629.         FSIImage.Quality = colors.selectedIndex + 1;
  630.         displayImage();
  631.     }
  632.         
  633.     function getFileName()
  634.     {
  635.         var theName = selection.GetField('Image');
  636.         theName = theName.split('\\');
  637.         return theName[theName.length - 1];
  638.     }
  639.     
  640.     function updateCatalog()
  641.     {
  642.         var column0 = app.GetSystemVar('nof_photoNameSize') - 0;
  643.         var column1 = app.GetSystemVar('nof_photoTitleSize') - 0;
  644.         var speed = app.GetSystemVar('nof_downloadSpeed') - 0;
  645.         
  646.         if (!column0 || !column1)
  647.         {
  648.             column0 = 92;
  649.             column1 = 135;
  650.             speed = 1;
  651.         }
  652.  
  653.         downloadSpeed.selectedIndex = speed;
  654.  
  655.         FSIListCtrl.AddColumn(dictionary.get('LabelColumnFileName'), column0);
  656.         FSIListCtrl.AddColumn(dictionary.get('LabelColumnTitle'), column1);
  657.  
  658.         if (selection)
  659.         {
  660.             for (var i = 0; i < count; i++)
  661.             {
  662.                 selection.SetIndex(indices[i]);
  663.                 var row = FSIListCtrl.AddRow(getFileName());
  664.                 FSIListCtrl.SetValue(row, 1, selection.GetField('Title'));
  665.             }
  666.  
  667.             if (count)
  668.             {            
  669.                 FSIListCtrl.Index = app.IntArg;
  670.                 selection.SetIndex(indices[app.IntArg]);
  671.                 updateItem();
  672.             }
  673.             else
  674.             {
  675.                 DeleteItem.disabled = true;
  676.                 DeleteAll.disabled = true;
  677.             }
  678.         }
  679.     }
  680.     
  681.     function updateIndex()
  682.     {
  683.         fIndexSettings.origTemplate = fIndexSettings.currentTemplate;
  684.         fIndexSettings.origSubTemplate = fIndexSettings.currentSubTemplate;
  685.         indexCatalog.Info = 
  686.             'length=' + fIndexSettings.length + '\n' +
  687.             'index=' + fIndexSettings.index + '\n' +
  688.             'flags=' + fIndexSettings.flags + '\n' +
  689.             'width=' + fIndexSettings.width + '\n' +
  690.             'height=' + fIndexSettings.height + '\n' +
  691.             'quality=' + fIndexSettings.quality + '\n' +
  692.             'template=' + fIndexSettings.currentTemplate + '\n' +
  693.             'subtemplate=' + fIndexSettings.currentSubTemplate + '\n' +
  694.             'borderColor=' + fIndexSettings.borderColor + '\n' +
  695.             'borderWidth=' + fIndexSettings.borderWidth;
  696.         indexCatalog.Settings = fIndexSettings.templateSettings;
  697.         indexCatalog.LsMaxWidth = fIndexSettings.lsMaxWidth;
  698.         indexCatalog.LsMaxHeight = fIndexSettings.lsMaxHeight;
  699.         indexCatalog.LsMinWidth = fIndexSettings.lsMinWidth;
  700.         indexCatalog.LsMinHeight = fIndexSettings.lsMinHeight;
  701.         indexCatalog.LsWidth = fIndexSettings.lsWidth;
  702.         indexCatalog.LsHeight = fIndexSettings.lsHeight;
  703.         indexCatalog.PtMaxWidth = fIndexSettings.ptMaxWidth;
  704.         indexCatalog.PtMaxHeight = fIndexSettings.ptMaxHeight;
  705.         indexCatalog.PtMinWidth = fIndexSettings.ptMinWidth;
  706.         indexCatalog.PtMinHeight = fIndexSettings.ptMinHeight;
  707.         indexCatalog.PtWidth = fIndexSettings.ptWidth;
  708.         indexCatalog.PtHeight = fIndexSettings.ptHeight;
  709.  
  710.         indexCatalog.HorizontalSpacing = fIndexSettings.horizontalSpacing;
  711.         indexCatalog.VerticalSpacing = fIndexSettings.verticalSpacing;
  712.     }
  713.     
  714.     function checkUpdateIndex()
  715.     {
  716.         if (formatType[1].checked &&
  717.             ((indexCatalog.Flags & INDEX_IS_TABLE) == 0 || 
  718.             fIndexSettings.origTemplate != fIndexSettings.currentTemplate ||
  719.             fIndexSettings.origSubTemplate != fIndexSettings.currentSubTemplate ||
  720.             ((indexCatalog.Flags & INDEX_INCLUDE_TITLE) != 0) != includeTitle.checked) ||
  721.             fIndexSettings.horizontalSpacing != indexCatalog.HorizontalSpacing ||
  722.             fIndexSettings.verticalSpacing != indexCatalog.VerticalSpacing ||
  723.             fIndexSettings.borderColor != fIndexSettings.origBorderColor ||
  724.             fIndexSettings.borderWidth != fIndexSettings.origBorderWidth)
  725.         {
  726.             indexModified = true;
  727.             updateIndex();
  728.             importIndexTable(fIndexSettings.origTemplate != fIndexSettings.currentTemplate || isInitial);
  729.         }
  730.  
  731.         var flags = indexCatalog.Flags;
  732.         
  733.         if (formatType[1].checked)
  734.             flags |= INDEX_IS_TABLE;
  735.         else
  736.             flags &= ~INDEX_IS_TABLE;
  737.         if (includeTitle.checked)
  738.             flags |= INDEX_INCLUDE_TITLE;
  739.         else
  740.             flags &= ~INDEX_INCLUDE_TITLE;
  741.  
  742.         if (indexCatalog.Flags != flags)
  743.         {
  744.             indexModified = true;
  745.             indexCatalog.Flags = flags;
  746.         }
  747.     }
  748.  
  749.     function updateDisplay()
  750.     {
  751.         displayModified = true;
  752.         fDisplaySettings.origTemplate = fDisplaySettings.currentTemplate;
  753.         fDisplaySettings.origSubTemplate = fDisplaySettings.currentSubTemplate;
  754.         displayCatalog.Info = 
  755.             'length=' + fDisplaySettings.length + '\n' +
  756.             'index=' + fDisplaySettings.index + '\n' +
  757.             'flags=' + fDisplaySettings.flags + '\n' +
  758.             'width=' + fDisplaySettings.width + '\n' +
  759.             'height=' + fDisplaySettings.height + '\n' +
  760.             'quality=' + fDisplaySettings.quality + '\n' +
  761.             'template=' + fDisplaySettings.currentTemplate + '\n' +
  762.             'subtemplate=' + fDisplaySettings.currentSubTemplate + '\n' +
  763.             'borderColor=' + fDisplaySettings.borderColor + '\n' +
  764.             'borderWidth=' + fDisplaySettings.borderWidth;
  765.         displayCatalog.Settings = fDisplaySettings.templateSettings;
  766.         displayCatalog.LsMaxWidth = fDisplaySettings.lsMaxWidth;
  767.         displayCatalog.LsMaxHeight = fDisplaySettings.lsMaxHeight;
  768.         displayCatalog.LsMinWidth = fDisplaySettings.lsMinWidth;
  769.         displayCatalog.LsMinHeight = fDisplaySettings.lsMinHeight;
  770.         displayCatalog.LsWidth = fDisplaySettings.lsWidth;
  771.         displayCatalog.LsHeight = fDisplaySettings.lsHeight;
  772.         displayCatalog.PtMaxWidth = fDisplaySettings.ptMaxWidth;
  773.         displayCatalog.PtMaxHeight = fDisplaySettings.ptMaxHeight;
  774.         displayCatalog.PtMinWidth = fDisplaySettings.ptMinWidth;
  775.         displayCatalog.PtMinHeight = fDisplaySettings.ptMinHeight;
  776.         displayCatalog.PtWidth = fDisplaySettings.ptWidth;
  777.         displayCatalog.PtHeight = fDisplaySettings.ptHeight;
  778.     }
  779.  
  780.     function checkUpdateDisplay()
  781.     {
  782.         if (fDisplaySettings.origTemplate != fDisplaySettings.currentTemplate ||
  783.             fDisplaySettings.origSubTemplate != fDisplaySettings.currentSubTemplate ||
  784.             fDisplaySettings.borderColor != fDisplaySettings.origBorderColor ||
  785.             fDisplaySettings.borderWidth != fDisplaySettings.origBorderWidth ||
  786.             isInitial)
  787.         {
  788.             displayModified = true;
  789.             updateDisplay();
  790.             importDisplayTable();
  791.         }
  792.  
  793.         var theLayoutId = 0;
  794.         
  795.         for (var i = 0; i < 7; i++)
  796.         {
  797.             if (layoutSelect[i].checked)
  798.             {
  799.                 theLayoutId = i;
  800.                 break;
  801.             }
  802.         }
  803.  
  804.         if ((displayCatalog.Flags & DISPLAY_LAYOUT_MASK) != theLayoutId || isInitial)
  805.         {
  806.             displayModified = true;
  807.             var path = wrapper.options[wrapper.selectedIndex].value;
  808.             var importer = new ActiveXObject('FSI.FSIImporter');
  809.             if (!importer.StartImport('.\\PhotoGallery\\Layout\\layout' + theLayoutId, true))
  810.                 return;
  811.             importer.OpenFile('index.html', false);
  812.             if (importer.NextTag('BODY'))
  813.             {
  814.                 importer.DeleteAttribute('BGCOLOR');
  815.                 importer.DeleteAttribute('BACKGROUND');
  816.                 importer.DeleteAttribute('TEXT');
  817.                 importer.DeleteAttribute('LINK');
  818.                 importer.DeleteAttribute('VLINK');
  819.                 importer.DeleteAttribute('ALINK');
  820.             }
  821.             
  822.             importer.CloseFile();
  823.             importer.ImportObject('index.html', displayCatalog, 3, true);
  824.             importer.DeleteImportDirectory();
  825.             flags = displayCatalog.Flags;
  826.             flags &= ~DISPLAY_LAYOUT_MASK;
  827.             flags |= theLayoutId;
  828.             displayCatalog.Flags = flags;
  829.         }
  830.  
  831.         isInitial = false;
  832.     }
  833.     
  834.     function onClose()
  835.     {
  836.         if (currentTab == 1 && fIndexSettings.origTemplate != template.options[template.selectedIndex].value)
  837.         {
  838.             indexModified = true;
  839.             setImageSizeAll();
  840.         }
  841.         
  842.         if (currentTab == 2 && fDisplaySettings.origTemplate != wrapper.options[wrapper.selectedIndex].value)
  843.         {
  844.             displayModified = true;
  845.             setImageSizeAll();
  846.         }
  847.  
  848.         save();
  849.         fIndexSettings.currentTemplate = template.options[template.selectedIndex].value;
  850.         fIndexSettings.currentSubTemplate = (templateStyle.selectedIndex != -1 ? templateStyle.options[templateStyle.selectedIndex].value : '');
  851.         fDisplaySettings.currentTemplate = wrapper.options[wrapper.selectedIndex].value;
  852.         fDisplaySettings.currentSubTemplate = (wrapperOptions.selectedIndex != -1 ? wrapperOptions.options[wrapperOptions.selectedIndex].value : '');
  853.  
  854.         checkUpdateIndex();
  855.         checkUpdateDisplay();
  856.         
  857.         var fieldName = '';
  858.         if (titleInBanner.checked)
  859.             fieldName = 'Title';
  860.             
  861.         if (fieldName != fFieldName)
  862.         {
  863.             displayModified = true;
  864.             theSelection.BannerNameField = fieldName;
  865.         }
  866.  
  867.         if (indexCatalog.Name != textLink.value)
  868.         {
  869.             indexCatalog.Name = textLink.value;
  870.             indexModified = true;
  871.         }
  872.         
  873.         if (indexCatalog.ColNo != columns.selectedIndex + 1)
  874.         {
  875.             indexModified = true;
  876.             indexCatalog.ColNo = columns.selectedIndex + 1;
  877.         }
  878.                 
  879.         if (seqChanged)
  880.         {
  881.             indexModified = true;
  882.             
  883.             for (var i = 0; i < count; i++)
  884.             {
  885.                 selection.SetIndex(indices[i]);
  886.                 selection.SetField('Position', i);
  887.                 selection.Update();
  888.             }
  889.         }
  890.  
  891.         var flags = 0;
  892.         if (indexModified)
  893.             flags += 1;
  894.         if (displayModified)
  895.             flags += 2;
  896.         app.IntArg = flags;
  897.  
  898.         if (listInit)
  899.         {
  900.             app.SetSystemVar('nof_photoNameSize', FSIListCtrl.GetColumnWidth(0));
  901.             app.SetSystemVar('nof_photoTitleSize', FSIListCtrl.GetColumnWidth(1));
  902.         }
  903.         
  904.         app.SetSystemVar('nof_downloadSpeed', downloadSpeed.selectedIndex);
  905.     }
  906.         
  907.     function add()
  908.     {
  909.         var s = app2.SelectMultipleFiles('');
  910.         if (s.length)
  911.         {
  912.             s = s.split('|');
  913.             var position = count;
  914.         
  915.             for (var i = 0; i < s.length; i++)
  916.             {
  917.                 var path = s[i];
  918.                 var quality;
  919.                 var tnquality;
  920.                 selection.NewRecord();
  921.                 selection.SetField('Position', count);
  922.                 selection.SetField('Image', path);
  923.                 selection.SetField('ImageFlags', 0);
  924.                 selection.SetField('ImageTnFlags', 0);
  925.                 
  926.                 path = path.split('.');
  927.                 if (path.length == 2)
  928.                 {
  929.                     path = path[1].toLowerCase();
  930.                     if (path == 'jpg' || path == 'jpeg')
  931.                     {
  932.                         quality = fDisplaySettings.quality;
  933.                         tnquality = fIndexSettings.quality;
  934.                     }
  935.                     else if (path == 'gif')
  936.                     {
  937.                         quality = 7;
  938.                         tnquality = 7;
  939.                     }
  940.                     else
  941.                     {
  942.                         path = 'jpg';
  943.                         quality = fDisplaySettings.quality;
  944.                         tnquality = fIndexSettings.quality;
  945.                     }
  946.                 }
  947.                 else
  948.                 {
  949.                     path = 'jpg';
  950.                     quality = fDisplaySettings.quality;
  951.                     tnquality = fIndexSettings.quality;
  952.                 }
  953.  
  954.                 selection.SetField('ImageQuality', quality);
  955.                 selection.SetField('ImageTnQuality', tnquality);
  956.                 selection.SetField('ImageFormat', path);
  957.                 selection.SetField('ImageTnFormat', path);
  958.                 selection.Update();
  959.                 
  960.                 var row = FSIListCtrl.AddRow(getFileName());
  961.                 FSIListCtrl.SetValue(row, 1, selection.GetField('Title'));
  962.                 indices[count] = count;
  963.                 count++;
  964.             }
  965.             
  966.             DeleteItem.disabled = (count == 0);
  967.             DeleteAll.disabled = (count == 0);
  968.             if (position)
  969.                 selection.SetIndex(indices[FSIListCtrl.Index]);
  970.             FSIListCtrl.Index = position;
  971.             FSIListCtrl.focus();
  972.             imageNo.innerText = selection.Count();
  973.         }
  974.     }
  975.     
  976.     function deleteItem()
  977.     {
  978.         getFromTab();
  979.         
  980.         if ((fDisplayImage.flags & TABLE_GENERATED_MASK) != 0)
  981.             theSelection.FreeKey(fImage.image, fDisplayImage.width, fDisplayImage.height, fImage.rotation, fDisplayImage.quality, fDisplayImage.format);
  982.  
  983.         if ((fIndexImage.flags & TABLE_GENERATED_MASK) != 0)
  984.             theSelection.FreeKey(fImage.image, fIndexImage.width, fIndexImage.height, fImage.rotation, fIndexImage.quality, fIndexImage.format);
  985.  
  986.         isUpdating = true;
  987.         index = FSIListCtrl.Index;
  988.         selection.SetIndex(indices[index]);
  989.         selection.DeleteRecord();
  990.         selection.Update();
  991.         FSIListCtrl.Delete();
  992.         var removedIndex = indices[index];
  993.         for (var i = index; i < count - 1; i++)
  994.             indices[i] = indices[i + 1];
  995.         for (var i = 0; i < count - 1; i++)
  996.         {
  997.             if (indices[i] > removedIndex)
  998.                 indices[i]--;
  999.         }
  1000.         if (index == selection.Count())
  1001.             index--;
  1002.         FSIListCtrl.Index = index;
  1003.         count--;
  1004.         seqChanged = true;
  1005.         
  1006.         if (!count)
  1007.         {
  1008.             DeleteItem.disabled = true;
  1009.             DeleteAll.disabled = true;
  1010.         }
  1011.         
  1012.         imageNo.innerText = selection.Count();
  1013.         FSIListCtrl.focus();
  1014.         isUpdating = false;
  1015.         isValid = false;
  1016.         forceUpdate = true;
  1017.         updateItem();
  1018.         updateTab();
  1019.     }
  1020.  
  1021.     function deleteAll()
  1022.     {
  1023.         if (!warning(dictionary.get('WarningDeleteAll'), 'question', 'nof_qpgremoveall'))
  1024.             return;
  1025.         getFromTab();
  1026.         isUpdating = true;
  1027.         FSIListCtrl.Index = 0;
  1028.  
  1029.         for (var i = count - 1; i >= 0; i--)
  1030.         {
  1031.             selection.SetIndex(index);
  1032.  
  1033.             var image = selection.GetField('Image');
  1034.             var displayflags = selection.GetField('ImageFlags') - 0;
  1035.             var displaywidth = selection.GetField('ImageWidth') - 0;
  1036.             var displayheight = selection.GetField('ImageHeight') - 0;
  1037.             var rotation = selection.GetField('ImageRotation') - 0;
  1038.             var displayquality = selection.GetField('ImageQuality') - 0;
  1039.             var displayformat = selection.GetField('ImageFormat');
  1040.             var indexflags = selection.GetField('ImageTnFlags') - 0;
  1041.             var indexwidth = selection.GetField('ImageTnWidth') - 0;
  1042.             var indexheight = selection.GetField('ImageTnHeight') - 0;
  1043.             var indexquality = selection.GetField('ImageTnQuality') - 0;
  1044.             var indexformat = selection.GetField('ImageTnFormat');
  1045.  
  1046.             if ((displayflags & TABLE_GENERATED_MASK) != 0)
  1047.                 theSelection.FreeKey(image, displaywidth, displayheight, rotation, displayquality, displayformat);
  1048.  
  1049.             if ((indexflags & TABLE_GENERATED_MASK) != 0)
  1050.                 theSelection.FreeKey(image, indexwidth, indexheight, rotation, indexquality, indexformat);
  1051.  
  1052.             selection.DeleteRecord();
  1053.             selection.Update();
  1054.             FSIListCtrl.Delete();
  1055.         }
  1056.  
  1057.         seqChanged = true;
  1058.             
  1059.         DeleteItem.disabled = true;
  1060.         DeleteAll.disabled = true;
  1061.     
  1062.         index = -1;
  1063.         count = 0;        
  1064.         imageNo.innerText = 0;
  1065.         FSIListCtrl.focus();
  1066.         isUpdating = false;
  1067.         isValid = false;
  1068.         forceUpdate = true;
  1069.         updateItem();
  1070.         updateTab();
  1071.     }
  1072.  
  1073.     function orientationToValue(i)
  1074.     {
  1075.         switch (i)
  1076.         {
  1077.             case 0:
  1078.                 return 0;
  1079.             case 1:
  1080.                 return 90;
  1081.             case 2:
  1082.                 return 270;
  1083.             default:
  1084.                 return 180;
  1085.         }
  1086.     }
  1087.     
  1088.     function orientationToIndex(v)
  1089.     {
  1090.         switch (v - 0)
  1091.         {
  1092.             case 0:
  1093.                 return 0;
  1094.             case 90:
  1095.                 return 1;
  1096.             case 270:
  1097.                 return 2;
  1098.             default:
  1099.                 return 3;
  1100.         }
  1101.     }
  1102.     
  1103.     function getFromTab()
  1104.     {
  1105.         if (isValid && currentTab1 >= 0)
  1106.         {
  1107.             var theFlags = 0;
  1108.             currentImage.flags = (currentImage.flags & 0xffffff00) | theFlags;
  1109.             currentImage.quality = quality.value - 0;
  1110.             currentImage.format = (imageType.selectedIndex ? 'gif' : 'jpg');
  1111.             
  1112.             if (imageType.selectedIndex)
  1113.                 currentImage.quality = colors.selectedIndex + 1 + 0x10000 * palette.selectedIndex;
  1114.         }
  1115.     }
  1116.     
  1117.     function updateTab()
  1118.     {
  1119.         if (isValid && currentTab1 >= 0)
  1120.         {
  1121.             FSIImage.SwitchImage();
  1122.             var updating = isUpdating;
  1123.             isUpdating = true;
  1124.             var theFlags = currentImage.flags;
  1125.             var isCreated = (theFlags & TABLE_GENERATED_MASK) != 0;
  1126.             FSIImage.IsCreated = isCreated;
  1127.             quality.value = currentImage.quality;
  1128.             updateQuality();
  1129.             imageType.selectedIndex = (currentImage.format == 'gif' ? 1 : 0);
  1130.             if (imageType.selectedIndex)
  1131.             {
  1132.                 jpeg.className="tabhide";
  1133.                 gif.className="tabshow";
  1134.                 prop.innerText = 'Palette:';
  1135.                 palette.selectedIndex = (currentImage.quality & 0xffff0000) / 0x10000;
  1136.                 if (!isCreated && !currentImage.quality)
  1137.                     currentImage.quality = FSIImage.Depth - 1;
  1138.                 colors.selectedIndex = (currentImage.quality & 0xffff) - 1;
  1139.                 FSIImage.Quality = colors.selectedIndex + 1;
  1140.                 FSIImage.Format = 'gif';
  1141.                 FSIImage.Palette = palette.selectedIndex;
  1142.             }
  1143.             else    
  1144.             {
  1145.                 gif.className="tabhide";
  1146.                 jpeg.className="tabshow";
  1147.                 prop.innerText = dictionary.get('LabelQuality');
  1148.                 FSIImage.Quality = quality.value - 0;
  1149.                 FSIImage.Format = 'jpg';
  1150.             }
  1151.  
  1152.             if (!isCreated)
  1153.             {
  1154.                 currentImage.flags |= TABLE_GENERATED_MASK;
  1155.                 updateSize();
  1156.             }
  1157.             
  1158.             FSIImage.Width = currentImage.width;
  1159.             FSIImage.Height = currentImage.height;
  1160.             FSIImage.Rotation = orientationToValue(orientation.selectedIndex);
  1161.             isUpdating = updating;
  1162.             displayImage();
  1163.         }
  1164.     }
  1165.  
  1166.     function save()
  1167.     {
  1168.         if (isValid)
  1169.         {
  1170.             var titleIschanged = fImage.title != title.value;
  1171.             var descriptionIsChanged = fImage.description != description.value;
  1172.             fImage.title = title.value;
  1173.             fImage.description = description.value;
  1174.             fImage.rotation = orientationToValue(orientation.selectedIndex);
  1175.  
  1176.             getFromTab();
  1177.             
  1178.             if (titleIschanged)
  1179.             {
  1180.                 selection.SetField('Title', fImage.title);
  1181.                 FSIListCtrl.SetValue(index, 1, title.value);
  1182.                 indexModified = true;
  1183.                 displayModified = true;
  1184.             }
  1185.             
  1186.             if (descriptionIsChanged)
  1187.             {
  1188.                 selection.SetField('Description', fImage.description);
  1189.                 displayModified = true;
  1190.             }
  1191.             
  1192.             if (oImage.rotation != fImage.rotation)
  1193.             {
  1194.                 selection.SetField('ImageRotation', fImage.rotation);
  1195.                 indexModified = true;
  1196.                 displayModified = true;
  1197.             }
  1198.  
  1199.             if (!imageAttributesEqual(oImage.display, fImage.display))
  1200.             {
  1201.                 selection.SetField('ImageFlags', fImage.display.flags);
  1202.                 selection.SetField('ImageWidth', fImage.display.width);
  1203.                 selection.SetField('ImageHeight', fImage.display.height);
  1204.                 selection.SetField('ImageQuality', fImage.display.quality);
  1205.                 selection.SetField('ImageFormat', fImage.display.format);
  1206.                 displayModified = true;
  1207.             }
  1208.  
  1209.             if (!imageAttributesEqual(oImage.index, fImage.index))
  1210.             {
  1211.                 selection.SetField('ImageTnFlags', fImage.index.flags);
  1212.                 selection.SetField('ImageTnWidth', fImage.index.width);
  1213.                 selection.SetField('ImageTnHeight', fImage.index.height);
  1214.                 selection.SetField('ImageTnQuality', fImage.index.quality);
  1215.                 selection.SetField('ImageTnFormat', fImage.index.format);
  1216.                 indexModified = true;
  1217.             }
  1218.         }
  1219.     }
  1220.     
  1221.     function updateItem()
  1222.     {
  1223.         if (isUpdating)
  1224.             return;
  1225.             
  1226.         if (!forceUpdate && index == FSIListCtrl.Index)
  1227.             return;
  1228.  
  1229.         forceUpdate = false;
  1230.         isUpdating = true;
  1231.         
  1232.         if (count == 0)
  1233.         {
  1234.             title.value = '';
  1235.             description.value = '';
  1236.             orientation.selectedIndex = 0;
  1237.             quality.value = 100;
  1238.             updateQuality();
  1239.             FSIImage.Unload();
  1240.             displayImage();
  1241.             isValid = false;
  1242.             isUpdating = false;
  1243.             return;
  1244.         }
  1245.  
  1246.         save();
  1247.                 
  1248.         index = FSIListCtrl.Index;
  1249.         selection.SetIndex(indices[index]);
  1250.  
  1251.         fImage.title = selection.GetField('Title');
  1252.         fImage.description = selection.GetField('Description');
  1253.         fImage.image = selection.GetField('Image');
  1254.         fImage.display.flags = selection.GetField('ImageFlags') - 0;
  1255.         fImage.display.width = selection.GetField('ImageWidth') - 0;
  1256.         fImage.display.height = selection.GetField('ImageHeight') - 0;
  1257.         fImage.rotation = selection.GetField('ImageRotation') - 0;
  1258.         fImage.display.quality = selection.GetField('ImageQuality') - 0;
  1259.         fImage.display.format = selection.GetField('ImageFormat');
  1260.         fImage.index.flags = selection.GetField('ImageTnFlags') - 0;
  1261.         fImage.index.width = selection.GetField('ImageTnWidth') - 0;
  1262.         fImage.index.height = selection.GetField('ImageTnHeight') - 0;
  1263.         fImage.index.quality = selection.GetField('ImageTnQuality') - 0;
  1264.         fImage.index.format = selection.GetField('ImageTnFormat');
  1265.         
  1266.         copyImageObjectAttributes(fImage, oImage);
  1267.  
  1268.         title.value = fImage.title;
  1269.         description.value = fImage.description;
  1270.         orientation.selectedIndex = orientationToIndex(fImage.rotation);
  1271.         FSIImage.Load(fImage.image);
  1272.         
  1273.         isValid = true;
  1274.         isUpdating = false;
  1275.     }
  1276.     
  1277.     function displayImage()
  1278.     {
  1279.         if (isUpdating )
  1280.             return;
  1281.         FSIImage.Display();
  1282.         var w = currentImage.width;
  1283.         var h = currentImage.height;
  1284.         if (w > FSIImage.clientWidth || h > FSIImage.clientHeight)
  1285.         {
  1286.             var ratiox = FSIImage.clientWidth / w;
  1287.             var ratioy = FSIImage.clientHeight / h;
  1288.             var ratio = (ratiox < ratioy ? ratiox : ratioy);
  1289.             ratio = toint(100 * ratio + 0.5);
  1290.             if (ratio < 1)
  1291.                 ratio = 1;
  1292.             else if (ratio > 99)
  1293.                 ratio = 99;
  1294.             previewScale.innerText = dictionary.get('LabelPreviewScale1') + ratio + dictionary.get('LabelPreviewScale2');
  1295.         }
  1296.         else
  1297.             previewScale.innerText = dictionary.get('LabelPreviewScale');
  1298.             
  1299.         var theSize = FSIImage.FileSize;
  1300.         var units = '';
  1301.  
  1302.         if (theSize > 1024)
  1303.         {
  1304.             theSize = theSize / 1024;
  1305.             units = ' KB';
  1306.         }
  1307.         if (theSize > 1024)
  1308.         {
  1309.             theSize = theSize / 1024;
  1310.             units = ' MB';
  1311.         }
  1312.         
  1313.         if (units.length)
  1314.         {
  1315.             theSize = '' + theSize;
  1316.             var s = theSize.split('.');
  1317.         
  1318.             theSize = s[0] + '.';
  1319.             if (s.length > 1)
  1320.                 theSize += s[1].substr(0, 1);
  1321.             else
  1322.                 theSize += '0';
  1323.         }
  1324.         
  1325.         fileSize.innerText = dictionary.get('LabelFileSize') + theSize + units;
  1326.         updateDownload();
  1327.     }
  1328.  
  1329.     function updateDownload()
  1330.     {
  1331.         var theSize = FSIImage.FileSize;
  1332.         var s;
  1333.  
  1334.         switch (downloadSpeed.selectedIndex)
  1335.         {
  1336.         case 0:
  1337.             s = 28800;
  1338.             break;
  1339.         case 1:
  1340.             s = 56600;
  1341.             break;
  1342.         case 2:
  1343.             s = 128000;
  1344.             break;
  1345.         case 3:
  1346.             s = 384000;
  1347.             break;
  1348.         case 4:
  1349.             s = 512000;
  1350.             break;
  1351.         default:
  1352.             s = 1540000;
  1353.             break;
  1354.         }
  1355.  
  1356.         var t = '' + theSize * 12 / s;
  1357.         t = t.split('.');
  1358.  
  1359.         if (t.length == 1 || t[0].length > 1)
  1360.             t = t[0];
  1361.         else
  1362.             t = t[0] + '.' + t[1].substr(0, 1);
  1363.         
  1364.         if (t == '0.0')
  1365.             t = '0.1';
  1366.  
  1367.         downloadTime.innerText = t;
  1368.     }
  1369.     
  1370.     function spin(o, v, f)
  1371.     {
  1372.         o.value = o.value - 0 + v;
  1373.         f();
  1374.     }
  1375.  
  1376.     function toint(i)
  1377.     {
  1378.         var s = '' + i;
  1379.         return s.split('.')[0] - 0;
  1380.     }
  1381.         
  1382.     function calcProportional()
  1383.     {
  1384.         var w = FSIImage.OrigWidth;
  1385.         var h = FSIImage.OrigHeight;
  1386.  
  1387.         if (orientation.selectedIndex == 1 || orientation.selectedIndex == 2)
  1388.         {
  1389.             var i = w;
  1390.             w = h;
  1391.             h = i;
  1392.         }
  1393.  
  1394.         var maxWidth = currentSettings.lsWidth;
  1395.         var maxHeight = currentSettings.lsHeight;
  1396.  
  1397.         if (w < h && currentSettings.ptWidth && currentSettings.ptHeight)
  1398.         {
  1399.             maxWidth = currentSettings.ptWidth;
  1400.             maxHeight = currentSettings.ptHeight;
  1401.         }
  1402.  
  1403.         var wscale = toint(1000 * w / maxWidth);
  1404.         var hscale = toint(1000 * h / maxHeight);
  1405.         var scale = (wscale > hscale) ? wscale : hscale;
  1406.  
  1407.         if (scale)
  1408.         {
  1409.             currentImage.width = toint(1000 * w / scale);
  1410.             currentImage.height = toint(1000 * h / scale);
  1411.         }
  1412.         else
  1413.         {
  1414.             currentImage.width = 0;
  1415.             currentImage.height = 0;
  1416.         }
  1417.     }
  1418.  
  1419.     function updateSize()
  1420.     {
  1421.         calcProportional();
  1422.  
  1423.         FSIImage.Width = currentImage.width;
  1424.         FSIImage.Height = currentImage.height;
  1425.         displayImage();
  1426.     }
  1427.     
  1428.     function updateQuality()
  1429.     {
  1430.         var q = quality.value - 0;
  1431.  
  1432.         if (isNaN(q))
  1433.         {
  1434.             q = 100;        
  1435.             quality.value = q;
  1436.         }
  1437.         else if (q < 0 || q > 100)
  1438.         {
  1439.             if (q < 0)
  1440.                 q = 0;
  1441.             else
  1442.                 q = 100;
  1443.             
  1444.             quality.value = q;
  1445.         }
  1446.  
  1447.         FSIImage.Quality = q;
  1448.         displayImage();
  1449.         
  1450.         var i = 3;
  1451.         if (q < 40)
  1452.             i = 0;
  1453.         else if (q < 76)
  1454.             i = 1;
  1455.         else if (q < 100)
  1456.             i = 2;
  1457.         
  1458.         if (qualityLevel.selectedIndex != i)
  1459.             qualityLevel.selectedIndex = i;
  1460.     }
  1461.     
  1462.     function setQuality()
  1463.     {
  1464.         var q = 100;
  1465.         
  1466.         switch (qualityLevel.selectedIndex)
  1467.         {
  1468.         case 0:
  1469.             q = 39;
  1470.             break;
  1471.         case 1:
  1472.             q = 75;
  1473.             break;
  1474.         case 2:
  1475.             q = 99;
  1476.             break;
  1477.         default:
  1478.             q = 100;
  1479.             break;
  1480.         }
  1481.         
  1482.         if (quality.value != q)
  1483.         {
  1484.             quality.value = q;
  1485.             updateQuality();
  1486.         }
  1487.     }
  1488.  
  1489.     function setOrientation()
  1490.     {
  1491.         // Clear out information for the other image.
  1492.         var otherImage = (currentTab1 ? fIndexImage : fDisplayImage);
  1493.         var theFlags = otherImage.flags;
  1494.  
  1495.         if ((otherImage.flags & TABLE_GENERATED_MASK) != 0)
  1496.         {
  1497.             theSelection.FreeKey(fImage.image, otherImage.width, otherImage.height, fImage.rotation, otherImage.quality, otherImage.format);
  1498.             otherImage.flags &= ~TABLE_GENERATED_MASK;
  1499.         }
  1500.  
  1501.         fImage.rotation = orientationToValue(orientation.selectedIndex);
  1502.         FSIImage.Rotation = fImage.rotation;
  1503.         updateSize()
  1504.     }
  1505.     
  1506.     function moveUp()
  1507.     {
  1508.         if (count < 2)
  1509.             return;
  1510.             
  1511.         isUpdating = true;
  1512.         index = FSIListCtrl.Index;
  1513.         var i = indices[index];
  1514.         
  1515.         if (index > 0)
  1516.         {
  1517.             indices[index] = indices[index - 1];
  1518.             indices[index - 1] = i;
  1519.             index--;
  1520.         }
  1521.         else
  1522.         {
  1523.             for (var j = 1; j < count; j++)
  1524.                 indices[j - 1] = indices[j];
  1525.  
  1526.             indices[count - 1] = i;
  1527.             index = count - 1;
  1528.         }
  1529.  
  1530.         selection.SetIndex(indices[index]);
  1531.         FSIListCtrl.MoveUp();
  1532.         seqChanged = true;
  1533.         FSIListCtrl.focus();
  1534.         isUpdating = false;
  1535.     }
  1536.  
  1537.     function moveDown()
  1538.     {
  1539.         if (count < 2)
  1540.             return;
  1541.             
  1542.         isUpdating = true;
  1543.         index = FSIListCtrl.Index;
  1544.         var i = indices[index];
  1545.  
  1546.         if (index < count - 1)
  1547.         {
  1548.             indices[index] = indices[index + 1];
  1549.             indices[index + 1] = i;
  1550.             index++;
  1551.         }
  1552.         else
  1553.         {
  1554.             for (var j = count - 1; j > 0; j--)
  1555.                 indices[j] = indices[j - 1];
  1556.  
  1557.             indices[0] = i;
  1558.             index = 0;
  1559.         }
  1560.  
  1561.         FSIListCtrl.MoveDown();
  1562.         seqChanged = true;
  1563.         FSIListCtrl.focus();
  1564.         isUpdating = false;
  1565.     }
  1566.  
  1567.     function selectLayout(i)
  1568.     {
  1569.         layoutSelect[i].click();
  1570.     }
  1571.  
  1572.     function updateIndexTab(isTable)
  1573.     {
  1574.         textLink.disabled = isTable;
  1575.         template.disabled = !isTable;
  1576.         templateStyle.disabled = !isTable;
  1577.         columns.disabled = !isTable;
  1578.         includeTitle.disabled = !fIndexSettings.titleEnabled || !isTable;
  1579.         includeTitleText.disabled = !fIndexSettings.titleEnabled || !isTable;
  1580.         indexFormatTitle.disabled = !fIndexSettings.titleEnabled || !isTable;
  1581.         borderwidth.disabled = !isTable;
  1582.         borderwidthup.disabled = !isTable;
  1583.         borderwidthdown.disabled = !isTable;
  1584.         bordercolorctl.disabled = !isTable;
  1585.         cellspacing.disabled = !isTable;
  1586.         cellspacingup.disabled = !isTable;
  1587.         cellspacingdown.disabled = !isTable;
  1588.         
  1589.         if (fIndexSettings.titleEnabled)
  1590.         {
  1591.             includeTitle.style.visibility = 'visible';
  1592.             includeTitleText.style.visibility = 'visible';
  1593.             indexFormatTitle.style.visibility = 'visible';
  1594.             indexFormatTitleHelp.style.visibility = 'visible';
  1595.         }
  1596.         else
  1597.         {
  1598.             includeTitle.style.visibility = 'hidden';
  1599.             includeTitleText.style.visibility = 'hidden';
  1600.             indexFormatTitle.style.visibility = 'hidden';
  1601.             indexFormatTitleHelp.style.visibility = 'hidden';
  1602.         }
  1603.     }
  1604.  
  1605.     function importIndexTable(overwriteFormat)
  1606.     {
  1607.         var path = template.options[template.selectedIndex].value;
  1608.         var importer = new ActiveXObject('FSI.FSIImporter');
  1609.         importer.StartImport('.\\PhotoGallery\\Spacer', true);
  1610.         if (!importer.AddFiles('.\\PhotoGallery\\Thumbnail\\' + path + '\\content', true))
  1611.             return;
  1612.         if (templateStyle.selectedIndex >= 0)
  1613.         {
  1614.             path += '\\options\\' + templateStyle.options[templateStyle.selectedIndex].value + '\\content';
  1615.             if (!importer.AddFiles('.\\PhotoGallery\\Thumbnail\\' + path, true))
  1616.                 return;
  1617.         }
  1618.  
  1619.         for (var i = 0; i < 2; i++)
  1620.         {
  1621.             var filename;
  1622.             if (i == 0)
  1623.                 filename = 'index.html';
  1624.             else
  1625.                 filename = 'portrait.html';
  1626.                 
  1627.             if (importer.OpenFile(filename, false))
  1628.             {
  1629.                 if (!includeTitle.checked || fIndexSettings.borderEnabled)
  1630.                 {
  1631.                     if (!includeTitle.checked && importer.NextId('NOFTitle'))
  1632.                     {
  1633.                         var removed = false;
  1634.  
  1635.                         if (fIndexSettings.titleDeleteRow)
  1636.                         {
  1637.                             if (importer.PrevTag('TR') && importer.PrevTag('TR'))
  1638.                             {
  1639.                                 var s = importer.OuterHTML;
  1640.                                 var l = s.length;
  1641.                                 var del = '';
  1642.                                 
  1643.                                 for (var i = 0; i < l; i++)
  1644.                                 {
  1645.                                     if (s.charCodeAt(i) != 13 && s.charCodeAt(i) != 10)
  1646.                                         del += s.charAt(i);
  1647.                                 }
  1648.  
  1649.                                 for (;;)
  1650.                                 {
  1651.                                     if (importer.PrevTag('TABLE'))
  1652.                                     {
  1653.                                         var s = importer.OuterHTML;
  1654.                                         var l = s.length;
  1655.                                         var content = '';
  1656.                                         
  1657.                                         for (var i = 0; i < l; i++)
  1658.                                         {
  1659.                                             if (s.charCodeAt(i) != 13 && s.charCodeAt(i) != 10)
  1660.                                                 content += s.charAt(i);
  1661.                                         }
  1662.  
  1663.                                         var i = content.search(del);
  1664.                                         
  1665.                                         if (i != -1)
  1666.                                         {
  1667.                                             content = content.substr(0, i) + content.substr(i + del.length);
  1668.                                             importer.OuterHTML = content;
  1669.                                             removed = true;
  1670.                                             break;
  1671.                                         }
  1672.                                     }
  1673.                                     else
  1674.                                         break;
  1675.                                 }
  1676.                             }
  1677.                         }
  1678.  
  1679.                         if (!removed)
  1680.                         {
  1681.                             importer.First();
  1682.                             if (importer.NextId('NOFTitle'))
  1683.                                 importer.OuterHTML = '<img height=1 width=1 src="./spacer.gif" vspace=0 hspace=0 border=0>';
  1684.                         }
  1685.                     }
  1686.             
  1687.                     if (fIndexSettings.borderEnabled && importer.First() && importer.NextId('PhotoTable'))
  1688.                     {
  1689.                         importer.SetAttribute('border', fIndexSettings.borderWidth);
  1690.                         importer.SetAttribute('bordercolor', fIndexSettings.borderColor);
  1691.                     }
  1692.                 
  1693.                     importer.First();
  1694.                 }
  1695.  
  1696.                 if (importer.NextTag('BODY'))
  1697.                 {
  1698.                     importer.DeleteAttribute('BGCOLOR');
  1699.                     importer.DeleteAttribute('BACKGROUND');
  1700.                     importer.DeleteAttribute('TEXT');
  1701.                     importer.DeleteAttribute('LINK');
  1702.                     importer.DeleteAttribute('VLINK');
  1703.                     importer.DeleteAttribute('ALINK');
  1704.                 }
  1705.             
  1706.                 importer.CloseFile();
  1707.             }
  1708.         }
  1709.         
  1710.         importer.ImportObject('index.html', indexCatalog, 1, overwriteFormat);
  1711.         importer.ImportObject('portrait.html', indexCatalog, 2, false);
  1712.         importer.DeleteImportDirectory();
  1713.     }
  1714.  
  1715.     function importDisplayTable()
  1716.     {
  1717.         var path = wrapper.options[wrapper.selectedIndex].value;
  1718.         var importer = new ActiveXObject('FSI.FSIImporter');
  1719.         if (!importer.StartImport('.\\PhotoGallery\\Photo\\' + path + '\\content', true))
  1720.             return;
  1721.         if (wrapperOptions.selectedIndex >= 0)
  1722.         {
  1723.             path += '\\options\\' + wrapperOptions.options[wrapperOptions.selectedIndex].value + '\\content';
  1724.             if (!importer.AddFiles('.\\PhotoGallery\\Photo\\' + path, true))
  1725.                 return;
  1726.         }
  1727.         var importDir = importer.GetImportDirectory(false) + '\\';
  1728.         if (app.DoesFileExist(importDir + 'NavLeft.gif'))
  1729.             displayCatalog.SetFile(1, importDir + 'NavLeft.gif');
  1730.         if (app.DoesFileExist(importDir + 'NavUp.gif'))
  1731.             displayCatalog.SetFile(2, importDir + 'NavUp.gif');
  1732.         if (app.DoesFileExist(importDir + 'NavRight.gif'))
  1733.             displayCatalog.SetFile(3, importDir + 'NavRight.gif');
  1734.             
  1735.         for (var i = 0; i < 2; i++)
  1736.         {
  1737.             var filename;
  1738.             if (i == 0)
  1739.                 filename = 'index.html';
  1740.             else
  1741.                 filename = 'portrait.html';
  1742.                 
  1743.             if (importer.OpenFile(filename, false))
  1744.             {
  1745.                 if (fDisplaySettings.borderEnabled)
  1746.                 {
  1747.                     if (importer.NextId('PhotoTable'))
  1748.                     {
  1749.                         importer.SetAttribute('border', fDisplaySettings.borderWidth);
  1750.                         importer.SetAttribute('bordercolor', fDisplaySettings.borderColor);
  1751.                     }
  1752.                 
  1753.                     importer.First();
  1754.                 }
  1755.  
  1756.                 if (importer.NextTag('BODY'))
  1757.                 {
  1758.                     importer.DeleteAttribute('BGCOLOR');
  1759.                     importer.DeleteAttribute('BACKGROUND');
  1760.                     importer.DeleteAttribute('TEXT');
  1761.                     importer.DeleteAttribute('LINK');
  1762.                     importer.DeleteAttribute('VLINK');
  1763.                     importer.DeleteAttribute('ALINK');
  1764.                 }
  1765.             
  1766.                 importer.CloseFile();
  1767.             }
  1768.         }
  1769.         
  1770.         importer.ImportObject('index.html', displayCatalog, 1, false);
  1771.         importer.ImportObject('portrait.html', displayCatalog, 2, false);
  1772.         importer.DeleteImportDirectory();
  1773.     }
  1774.  
  1775.     function updateTemplate()
  1776.     {
  1777.         for (var i = currentTemplateSettings.subTemplate.options.length - 1; i >= 0; i--)
  1778.             currentTemplateSettings.subTemplate.options.remove(i);
  1779.  
  1780.         initTemplateCombo(currentTemplateSettings.subTemplate, currentTemplateSettings.path + '\\' + currentTemplateSettings.template.options[currentTemplateSettings.template.selectedIndex].value + '\\options', '');
  1781.         
  1782.         currentTemplateSettings.currentTemplate = currentTemplateSettings.template.options[currentTemplateSettings.template.selectedIndex].value;
  1783.         currentTemplateSettings.currentSubTemplate = (currentTemplateSettings.subTemplate.options.length ? 
  1784.                                                         currentTemplateSettings.subTemplate.options[currentTemplateSettings.subTemplate.selectedIndex].value :
  1785.                                                         '');
  1786.  
  1787.         updateStyle(currentTemplateSettings);
  1788.  
  1789.         if (currentTemplateSettings == fIndexSettings)
  1790.         {
  1791.             if (currentTemplateSettings.subTemplate.options.length)
  1792.                 templateStyleDiv.className="tabshow";
  1793.             else
  1794.                 templateStyleDiv.className="tabhide";
  1795.  
  1796.             includeTitle.disabled = !fIndexSettings.titleEnabled;
  1797.             includeTitleText.disabled = !fIndexSettings.titleEnabled;
  1798.             includeTitle.checked = fIndexSettings.titleSet;
  1799.             indexFormatTitle.disabled = !fIndexSettings.titleEnabled;
  1800.  
  1801.             if (fIndexSettings.titleEnabled)
  1802.             {
  1803.                 includeTitle.style.visibility = 'visible';
  1804.                 includeTitleText.style.visibility = 'visible';
  1805.                 indexFormatTitle.style.visibility = 'visible';
  1806.                 indexFormatTitleHelp.style.visibility = 'visible';
  1807.             }
  1808.             else
  1809.             {
  1810.                 includeTitle.style.visibility = 'hidden';
  1811.                 includeTitleText.style.visibility = 'hidden';
  1812.                 indexFormatTitle.style.visibility = 'hidden';
  1813.                 indexFormatTitleHelp.style.visibility = 'hidden';
  1814.             }
  1815.  
  1816.             if (!currentTemplateSettings.subTemplate.options.length)
  1817.             {
  1818.                 if (fIndexSettings.borderEnabled)
  1819.                 {
  1820.                     colorStyleDiv.className="tabshow";
  1821.                     bordercolorctl.style.backgroundColor = fIndexSettings.borderColor;
  1822.                     borderwidth.value = fIndexSettings.borderWidth;
  1823.                 }
  1824.                 else
  1825.                     colorStyleDiv.className="tabhide";
  1826.             }
  1827.             else
  1828.                 colorStyleDiv.className="tabhide";
  1829.         
  1830.             if (fIndexSettings.spacingEnabled)
  1831.             {
  1832.                 cellSpacingDiv.className="tabshow";
  1833.                 cellspacing.value = fIndexSettings.horizontalSpacing;
  1834.             }
  1835.             else
  1836.                 cellSpacingDiv.className="tabhide";
  1837.         }
  1838.         
  1839.         if (currentTemplateSettings == fDisplaySettings)
  1840.         {
  1841.             if (wrapperOptions.options.length)
  1842.             {
  1843.                 displayColorStyleDiv.className="tabhide";
  1844.                 wrapperOptionsDiv.className="tabshow";
  1845.             }
  1846.             else
  1847.             {
  1848.                 wrapperOptionsDiv.className="tabhide";
  1849.                 
  1850.                 if (fDisplaySettings.borderEnabled)
  1851.                 {
  1852.                     displayColorStyleDiv.className="tabshow";
  1853.                     displaybordercolorctl.style.backgroundColor = fDisplaySettings.borderColor;
  1854.                     displayborderwidth.value = fDisplaySettings.borderWidth;
  1855.                 }
  1856.                 else
  1857.                     displayColorStyleDiv.className="tabhide";
  1858.             }
  1859.         }
  1860.  
  1861.         if (currentTemplateSettings.subTemplate.options.length)
  1862.             currentTemplateSettings.subTemplate.selectedIndex = 0;
  1863.     }
  1864.  
  1865.     function updateStyle(settings)
  1866.     {
  1867.         updateInfo(settings);
  1868.         updatePreview(settings);
  1869.     }
  1870.     
  1871.     function updateInfo(settings)
  1872.     {
  1873.         var path = './PhotoGallery/' + settings.path + '/' + settings.template.options[settings.template.selectedIndex].value;
  1874.         var optpath = settings.subTemplate.selectedIndex >= 0 ? '/options/' + settings.subTemplate.options[settings.subTemplate.selectedIndex].value : '';
  1875.         
  1876.         if (app.DoesFileExist(path + optpath + '/info.txt'))
  1877.             updateSettings(app2.ReadFile(path + optpath + '/info.txt'), settings);
  1878.         else
  1879.             updateSettings(app2.ReadFile(path + '/info.txt'), settings);
  1880.     }
  1881.     
  1882.     function updatePreview(settings)
  1883.     {
  1884.         var path = settings.path + '/' + 
  1885.                     settings.template.options[settings.template.selectedIndex].value +
  1886.                     (settings.subTemplate.selectedIndex >= 0 ? '/options/' + settings.subTemplate.options[settings.subTemplate.selectedIndex].value : '') +
  1887.                     '/preview.jpg';
  1888.  
  1889.         settings.preview.src = (app.DoesFileExist('./PhotoGallery/' + path) ? './' + path : './../resources/images/clearpixel.gif');
  1890.     }
  1891.  
  1892.     function updateSettings(s, settings)
  1893.     {
  1894.         var description = '';
  1895.         settings.templateSettings = s;
  1896.         settings.titleSet = true;
  1897.         settings.titleEnabled = true;
  1898.         settings.titleDeleteRow = false;
  1899.         settings.lsMaxWidth = 2048;
  1900.         settings.lsMaxHeight = 2048;
  1901.         settings.lsMinWidth = 0;
  1902.         settings.lsMinHeight = 0;
  1903.         settings.lsWidth = 0;
  1904.         settings.lsHeight = 0;
  1905.         settings.ptMaxWidth = 0;
  1906.         settings.ptMaxHeight = 0;
  1907.         settings.ptMinWidth = 0;
  1908.         settings.ptMinHeight = 0;
  1909.         settings.ptWidth = 0;
  1910.         settings.ptHeight = 0;
  1911.         settings.borderEnabled = false;
  1912.         settings.borderColor = 0;
  1913.         settings.borderWidth = 0;
  1914.         settings.spacingEnabled = false;
  1915.         settings.horizontalSpacing = 0;
  1916.         settings.verticalSpacing = 0;
  1917.         s = s.split('\n');
  1918.         for (var i = 0; i < s.length; i++)
  1919.         {
  1920.             var p = s[i].split(',');
  1921.             if (p[0] == 'description')
  1922.             {
  1923.                 description = '';
  1924.                 
  1925.                 if (p.length > 1)
  1926.                     description = p[1];
  1927.                     
  1928.                 for (var j = 2; j < p.length; j++)
  1929.                     description += ',' + p[j];
  1930.             }
  1931.             else if (p[0] == 'landscape')
  1932.             {
  1933.                 var maxWidth = 2048;
  1934.                 var maxHeight = 2048;
  1935.                 var minWidth = 0;
  1936.                 var minHeight = 0;
  1937.                 var width = 0;
  1938.                 var height = 0;
  1939.  
  1940.                 for (var j = 1; j < p.length; j++)
  1941.                 {
  1942.                     var size = p[j].split('=');
  1943.  
  1944.                     if (size.length != 2)
  1945.                         continue;
  1946.                     if (size[0] == 'maxwidth')
  1947.                         maxWidth = size[1] - 0;
  1948.                     else if (size[0] == 'maxheight')
  1949.                         maxHeight = size[1] - 0;
  1950.                     else if (size[0] == 'minwidth')
  1951.                         minWidth = size[1] - 0;
  1952.                     else if (size[0] == 'minheight')
  1953.                         minHeight = size[1] - 0;
  1954.                     else if (size[0] == 'width')
  1955.                         width = size[1] - 0;
  1956.                     else if (size[0] == 'height')
  1957.                         height = size[1] - 0;
  1958.                 }
  1959.  
  1960.                 settings.lsMaxWidth = maxWidth;
  1961.                 settings.lsMaxHeight = maxHeight;
  1962.                 settings.lsMinWidth = minWidth;
  1963.                 settings.lsMinHeight = minHeight;
  1964.                 settings.lsWidth = width;
  1965.                 settings.lsHeight = height;
  1966.             }
  1967.             else if (p[0] == 'portrait')
  1968.             {
  1969.                 var maxWidth = 2048;
  1970.                 var maxHeight = 2048;
  1971.                 var minWidth = 0;
  1972.                 var minHeight = 0;
  1973.                 var width = 0;
  1974.                 var height = 0;
  1975.  
  1976.                 for (var j = 1; j < p.length; j++)
  1977.                 {
  1978.                     var size = p[j].split('=');
  1979.  
  1980.                     if (size.length != 2)
  1981.                         continue;
  1982.                     if (size[0] == 'maxwidth')
  1983.                         maxWidth = size[1] - 0;
  1984.                     else if (size[0] == 'maxheight')
  1985.                         maxHeight = size[1] - 0;
  1986.                     else if (size[0] == 'minwidth')
  1987.                         minWidth = size[1] - 0;
  1988.                     else if (size[0] == 'minheight')
  1989.                         minHeight = size[1] - 0;
  1990.                     else if (size[0] == 'width')
  1991.                         width = size[1] - 0;
  1992.                     else if (size[0] == 'height')
  1993.                         height = size[1] - 0;
  1994.                 }
  1995.  
  1996.                 settings.ptMaxWidth = maxWidth;
  1997.                 settings.ptMaxHeight = maxHeight;
  1998.                 settings.ptMinWidth = minWidth;
  1999.                 settings.ptMinHeight = minHeight;
  2000.                 settings.ptWidth = width;
  2001.                 settings.ptHeight = height;
  2002.             }
  2003.             else if (p[0] == 'title')
  2004.             {
  2005.                 for (var j = 1; j < p.length; j++)
  2006.                 {
  2007.                     var title = p[j].split('=');
  2008.  
  2009.                     if (title.length != 2)
  2010.                         continue;
  2011.                     if (title[0] == 'set')
  2012.                         settings.titleSet = title[1] == 'true';
  2013.                     else if (title[0] == 'enabled')
  2014.                         settings.titleEnabled = title[1] == 'true';
  2015.                     else if (title[0] == 'delete')
  2016.                         settings.titleDeleteRow = title[1] == 'row';
  2017.                 }
  2018.             }
  2019.             else if (p[0] == 'border')
  2020.             {
  2021.                 for (var j = 1; j < p.length; j++)
  2022.                 {
  2023.                     var opt = p[j].split('=');
  2024.  
  2025.                     if (opt.length != 2)
  2026.                         continue;
  2027.                     if (opt[0] == 'color')
  2028.                         settings.borderColor = opt[1] - 0;
  2029.                     else if (opt[0] == 'width')
  2030.                         settings.borderWidth = opt[1] - 0;
  2031.                     else if (opt[0] == 'enabled')
  2032.                         settings.borderEnabled = opt[1] == 'true';
  2033.                 }
  2034.             }
  2035.             else if (p[0] == 'spacing')
  2036.             {
  2037.                 for (var j = 1; j < p.length; j++)
  2038.                 {
  2039.                     var opt = p[j].split('=');
  2040.  
  2041.                     if (opt.length != 2)
  2042.                         continue;
  2043.                     if (opt[0] == 'size')
  2044.                     {
  2045.                         settings.horizontalSpacing = opt[1] - 0;
  2046.                         settings.verticalSpacing = opt[1] - 0;
  2047.                     }
  2048.                     else if (opt[0] == 'width')
  2049.                         settings.horizontalSpacing = opt[1] - 0;
  2050.                     else if (opt[0] == 'height')
  2051.                         settings.verticalSpacing = opt[1] - 0;
  2052.                     else if (opt[0] == 'enabled')
  2053.                         settings.spacingEnabled = opt[1] == 'true';
  2054.                 }
  2055.             }
  2056.         }
  2057.  
  2058.         settings.quality = 85;
  2059.         settings.description.location = description;
  2060.     }
  2061.     
  2062.     function format(field, catalog)
  2063.     {
  2064.         if (catalog == indexCatalog)
  2065.         {
  2066.             indexModified = true;
  2067.             checkUpdateIndex();
  2068.         }
  2069.         else
  2070.         {
  2071.             displayModified = true;
  2072.             checkUpdateDisplay();
  2073.         }
  2074.         catalog.EditFormat(theSelection, 1, field);
  2075.     }
  2076.     
  2077.     function oncaption()
  2078.     {
  2079.         if (!window.dialogArguments && fImage.description.length && fImage.description == description.value)
  2080.             message(dictionary.get('WarningOnCaption'), 'info', 'nof_qpgchangecaption', 8);
  2081.     }
  2082.                 
  2083.     function applyToAll()
  2084.     {
  2085.         var sub = (currentTab1 ? '' : 'Tn');
  2086.         getFromTab();
  2087.  
  2088.         for (var i = 0; i < count; i++)
  2089.         {
  2090.             if (i == index)
  2091.                 continue;
  2092.  
  2093.             selection.SetIndex(indices[i]);
  2094.             var image = selection.GetField('Image');
  2095.             var rotation = selection.GetField('ImageRotation') - 0;
  2096.             var flags = selection.GetField('Image' + sub + 'Flags') - 0;
  2097.             var quality = selection.GetField('Image' + sub + 'Quality') - 0;
  2098.             var format = selection.GetField('Image' + sub + 'Format').toLowerCase();
  2099.  
  2100.             if (format != currentImage.format || quality != currentImage.quality)
  2101.             {
  2102.                 selection.SetField('Image' + sub + 'Quality', currentImage.quality);
  2103.                 selection.SetField('Image' + sub + 'Format', currentImage.format);
  2104.  
  2105.                 if ((flags & TABLE_GENERATED_MASK) != 0)
  2106.                 {
  2107.                     var width = selection.GetField('Image' + sub + 'Width') - 0;
  2108.                     var height = selection.GetField('Image' + sub + 'Height') - 0;
  2109.                     theSelection.FreeKey(image, width, height, rotation, quality, format);
  2110.                     flags &= ~TABLE_GENERATED_MASK;
  2111.                     selection.SetField('Image' + sub + 'Flags', flags);
  2112.                 }
  2113.             }
  2114.         }
  2115.  
  2116.         selection.SetIndex(indices[index]);
  2117.     }
  2118.         
  2119.     function setImageSizeAll()
  2120.     {
  2121.         var sub = (currentTab == 2 ? '' : 'Tn');
  2122.         getFromTab();
  2123.  
  2124.         for (var i = 0; i < count; i++)
  2125.         {
  2126.             selection.SetIndex(indices[i]);
  2127.             var flags = selection.GetField('Image' + sub + 'Flags') - 0;
  2128.  
  2129.             if ((flags & TABLE_GENERATED_MASK) != 0)
  2130.             {
  2131.                 var w = selection.GetField('Image' + sub + 'Width') - 0;
  2132.                 var h = selection.GetField('Image' + sub + 'Height') - 0;
  2133.  
  2134.                 var maxWidth = currentSettings.lsWidth;
  2135.                 var maxHeight = currentSettings.lsHeight;
  2136.  
  2137.                 if (w < h && currentSettings.ptWidth && currentSettings.ptHeight)
  2138.                 {
  2139.                     maxWidth = currentSettings.ptWidth;
  2140.                     maxHeight = currentSettings.ptHeight;
  2141.                 }
  2142.  
  2143.                 var wscale = toint(1000 * w / maxWidth);
  2144.                 var hscale = toint(1000 * h / maxHeight);
  2145.                 var scale = (wscale > hscale ? wscale : hscale);
  2146.  
  2147.                 if (scale != 1000)
  2148.                 {
  2149.                     var image = selection.GetField('Image');
  2150.                     var rotation = selection.GetField('ImageRotation') - 0;
  2151.                     var quality = selection.GetField('Image' + sub + 'Quality') - 0;
  2152.                     var format = selection.GetField('Image' + sub + 'Format').toLowerCase();
  2153.  
  2154.                     theSelection.FreeKey(image, w, h, rotation, quality, format);
  2155.                     flags &= ~TABLE_GENERATED_MASK;
  2156.                     selection.SetField('Image' + sub + 'Flags', flags);
  2157.                 }
  2158.  
  2159.                 if (i == index)
  2160.                 {
  2161.                     if (currentTab == 2)
  2162.                         fDisplayImage.flags = flags;
  2163.                     else
  2164.                         fIndexImage.flags = flags;
  2165.                 }
  2166.             }
  2167.         }
  2168.  
  2169.         selection.SetIndex(indices[index]);
  2170.     }
  2171.  
  2172.     function selectColor(o)
  2173.     {
  2174.         var color = app2.SelectNewColor(fIndexSettings.borderColor);
  2175.         if (color != 0xffffffff)
  2176.         {
  2177.             o.style.backgroundColor = color;
  2178.             fIndexSettings.borderColor = color;
  2179.         }
  2180.     }
  2181.         
  2182.     function updateBorderWidth()
  2183.     {
  2184.         var w = borderwidth.value - 0;
  2185.         if (isNaN(w))
  2186.             w = 0;
  2187.         else if (w < 0)
  2188.             w = 0;
  2189.         else if (w > 1000)
  2190.             w = 1000;
  2191.          
  2192.         borderwidth.value = w;
  2193.         fIndexSettings.borderWidth = w;
  2194.     }
  2195.     
  2196.     function updateCellSpacing()
  2197.     {
  2198.         var w = cellspacing.value - 0;
  2199.         if (isNaN(w))
  2200.             w = 0;
  2201.         else if (w < 0)
  2202.             w = 0;
  2203.         else if (w > 10000)
  2204.             w = 10000;
  2205.             
  2206.         cellspacing.value = w;
  2207.         fIndexSettings.horizontalSpacing = w;
  2208.         fIndexSettings.verticalSpacing = w;
  2209.     }
  2210.     
  2211.     function selectDisplayColor(o)
  2212.     {
  2213.         var color = app2.SelectNewColor(fDisplaySettings.borderColor);
  2214.         if (color != 0xffffffff)
  2215.         {
  2216.             o.style.backgroundColor = color;
  2217.             fDisplaySettings.borderColor = color;
  2218.         }
  2219.     }
  2220.         
  2221.     function updateDisplayBorderWidth()
  2222.     {
  2223.         var w = displayborderwidth.value - 0;
  2224.         if (isNaN(w))
  2225.             w = 0;
  2226.         else if (w < 0)
  2227.             w = 0;
  2228.         else if (w > 1000)
  2229.             w = 1000;
  2230.          
  2231.         displayborderwidth.value = w;
  2232.         fDisplaySettings.borderWidth = w;
  2233.     }
  2234.  
  2235.     function helpFormat(o)
  2236.     {
  2237.         var oPopup = window.createPopup();
  2238.         var oPopBody = oPopup.document.body;
  2239.         oPopBody.style.backgroundColor = "lightyellow";
  2240.         oPopBody.style.border = "solid black 1px";
  2241.         oPopBody.innerHTML = "<table cellpadding=\"10\" cellspacing=\"0\" border=\"0\" width=\"100%\" height=\"100%\"><tr><td><font " + dictionary.get('NoteFontAttrs') + "><b>" + dictionary.get('NoteLabel') + "</b>" + dictionary.get('NoteText') + "</font></td></tr></table>";
  2242.         oPopup.show(-150, 10, dictionary.get('NoteWidth') * app2.LogPixelsX / 96, dictionary.get('NoteHeight') * app2.LogPixelsY / 96, o);
  2243.     }
  2244.